package com.ymatou.iapi.exp.testcase;

import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.exp.parameter.ChangeUserCoinBean;
import com.ymatou.iapi.exp.service.ChangeUserCoinCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

import com.ymttest.business.service.ExpCallService;
import com.ymttest.database.model.UserCoin;
import com.ymttest.database.model.UserCoinRecord;
import com.ymttest.database.sqlwapper.ExpWapper;

/**
 * 直接增加/扣除用户金币接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_ChangeUserCoin {
	private static ChangeUserCoinBean changeusercoinBean;
	private static ChangeUserCoinCall changeusercoinCall;
	private static ExpWapper ExpWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("直接增加/扣除用户金币接口");
	}

	@Before
	public void caseUp() {
		changeusercoinBean = new ChangeUserCoinBean();
		changeusercoinCall = new ChangeUserCoinCall();
		ExpWapper = new ExpWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(changeusercoinCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void verifyDB(ChangeUserCoinBean changeusercoin) {
		List<UserCoinRecord> records = ExpWapper.selectUserCoinRecord(changeusercoin.getUserId(), changeusercoin.getBizCode(), changeusercoin.getBizNo(), null);
		Logger.debug(FormatUtil.beanToGSONString(records));
		Logger.verifyEquals(true, records.size() > 0, "验证有记录");
		if (records.size() > 0) {
			UserCoinRecord record = records.get(0);
			Logger.verifyEquals(changeusercoin.getUserId(), record.getUserId(), "验证userid");
			Logger.verifyEquals(changeusercoin.getBizCode(), record.getBizCode().toString(), "验证BizCode");
			Logger.verifyEquals(changeusercoin.getBizNo(), record.getBizNo(), "验证getBizNo");
			if(changeusercoin.getBizCode().equals("200201") || changeusercoin.getBizCode().equals("200202") || changeusercoin.getBizCode().equals("200203")){
				Logger.verifyEquals(changeusercoin.getCoin()*-1,record.getTotalCoin(), "验证getCoin");
			}else{
				Logger.verifyEquals(changeusercoin.getCoin(), record.getTotalCoin(), "验证getCoin");
			}
			if (!(changeusercoin.getBizCode().equals("200201") || changeusercoin.getBizCode().equals("200203"))) {
				Logger.verifyEquals(changeusercoin.getBizNo(), record.getOriginalNo(), "验证getOriginalNo");
			}
		}

	}
	private void verifyDB(ChangeUserCoinBean changeusercoin,int coin) {
		List<UserCoinRecord> records = ExpWapper.selectUserCoinRecord(changeusercoin.getUserId(), changeusercoin.getBizCode(), changeusercoin.getBizNo(), null);
		Logger.debug(FormatUtil.beanToGSONString(records));
		Logger.verifyEquals(true, records.size() > 0, "验证有记录");
		if (records.size() > 0) {
			UserCoinRecord record = records.get(0);
			Logger.verifyEquals(changeusercoin.getUserId(), record.getUserId(), "验证userid");
			Logger.verifyEquals(changeusercoin.getBizCode(), record.getBizCode().toString(), "验证BizCode");
			Logger.verifyEquals(changeusercoin.getBizNo(), record.getBizNo(), "验证getBizNo");
			if(changeusercoin.getBizCode().equals("200201") || changeusercoin.getBizCode().equals("200202") || changeusercoin.getBizCode().equals("200203")){
				Logger.verifyEquals(coin, record.getCurCoin(), "验证getCoin");
			}else{
				Logger.verifyEquals(coin, record.getCurCoin(), "验证getCoin");
			}
			if (!(changeusercoin.getBizCode().equals("200201") || changeusercoin.getBizCode().equals("200203"))) {
				Logger.verifyEquals(changeusercoin.getBizNo(), record.getOriginalNo(), "验证getOriginalNo");
			}
		}

	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangeUserCoin_001() {
		Logger.start(true, "签到获得金币200101");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.resetCoinAccount(uid);
			Integer c1 = ExpCallService.getUserCoin(uid);
			changeusercoinBean.setBizCode("200101");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMdd"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_002() {
		Logger.start(true, "抽奖中奖获得金币200105");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			Integer c1 = ExpCallService.getUserCoin(uid);
			changeusercoinBean.setBizCode("200105");
			//流水号
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_003() {
		Logger.start(true, "抽奖扣除金币200202");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200202");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(Math.abs(c2-c1),changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_004() {
		Logger.start(true, "主动兑换优惠券200203");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200203");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c1-c2,changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);


		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	@Ignore
//	主动评价订单获得金币不使用此接口
//	 URL:http://exp.iapi.ymatou.com/api/addUserCoinFromEvaluation
	public void Tc_ChangeUserCoin_005() {
		Logger.start(true, "分享评价获得金币200104");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200104");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_006() {
		Logger.start(true, "设置昵称200106");
		try {
			Integer uid = TestDataManager.getRandomIntNum(2);
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200106");
			changeusercoinBean.setBizNo(uid.toString());
			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(5, changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			//设置昵称 默认5
			verifyDB(changeusercoinBean,5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_007() {
		Logger.start(true, "上传头像200107");
		try {
			Integer uid = TestDataManager.getRandomIntNum(2);
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200107");
			changeusercoinBean.setBizNo(uid.toString());
			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(5, changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			//上传头像 默认5
			verifyDB(changeusercoinBean,5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_008() {
		Logger.start(true, "绑定微信200108");
		try {
			Integer uid = TestDataManager.getRandomIntNum(2);
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200108");
			changeusercoinBean.setBizNo(uid.toString());
			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(5, changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			//绑定微信 默认5
			verifyDB(changeusercoinBean,5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_009() {
		Logger.start(true, "设置购物喜好200109");
		try {
			Integer uid = TestDataManager.getRandomIntNum(2);
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200109");
			changeusercoinBean.setBizNo(uid.toString());
			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(5, changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			//设置购物喜好 默认5
			verifyDB(changeusercoinBean,5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_010() {
		Logger.start(true, "添加身份信息200110");
		try {
			Integer uid = TestDataManager.getRandomIntNum(2);
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200110");
			changeusercoinBean.setBizNo(uid.toString());
			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(5, changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c2-c1,changeusercoinCall.getCoin(), "验证coin");
			//添加身份信息 默认5
			verifyDB(changeusercoinBean,5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ChangeUserCoin_011() {
		Logger.start(true, "不输入userid失败");
		try {
			changeusercoinBean.setBizCode("200101");
			changeusercoinBean.setBizNo("200101");
//			changeusercoinBean.setUserId(uid);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("2", changeusercoinCall.getString("Code"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ChangeUserCoin_012() {
		Logger.start(true, "不输入bizcode失败");
		try {
//			changeusercoinBean.setBizCode("200101");
			changeusercoinBean.setBizNo("200101");
			changeusercoinBean.setUserId(1);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("2", changeusercoinCall.getString("Code"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_ChangeUserCoin_013() {
		Logger.start(true, "不输入bizno失败");
		try {

			changeusercoinBean.setBizCode("200101");
//			changeusercoinBean.setBizNo("200101");
			changeusercoinBean.setUserId(1);
//			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("2", changeusercoinCall.getString("Code"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangeUserCoin_014() {
		Logger.start(true, "重复签到失败");
		try {
			changeusercoinBean.setBizCode("200101");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMdd"));
			changeusercoinBean.setUserId(1);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("4", changeusercoinCall.getString("Code"), "验证Code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_ChangeUserCoin_015() {
		Logger.start(true, "新用户第一次获得金币创建账号成功");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.resetCoinAccount(uid);
			Integer c1 = ExpCallService.getUserCoin(uid);
			changeusercoinBean.setBizCode("200101");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMdd"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(changeusercoinBean.getCoin(), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.verifyEquals(Math.abs(c2-c1), changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_016() {
		Logger.start(false, "抽奖扣除金币,金币余额不足");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.resetCoinAccount(uid);
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 10);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200202");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(20);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("3", changeusercoinCall.getString("Code"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_017() {
		Logger.start(true, "抽奖扣除金币200202传入负数时失败");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.ChangeUserCoin(uid, "200101", YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"), 100);
			Integer c1 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c1);
			changeusercoinBean.setBizCode("200202");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(-10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyIsContains("参数不能小于0", changeusercoinCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_018() {
		Logger.start(false, "抽奖扣除金币,只有去年金币且余额不足");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.resetCoinAccount(uid);
			int coin=15;
			UserCoin uc=new UserCoin();
			uc.setCoin(coin);
			uc.setUserId(uid);
			uc.setYear(Integer.valueOf(YMTDateUtil.getSysTime("yyyy"))-1);
			ExpWapper.insertUserCoin(uc);
			Logger.comment("now_coin:"+coin);
			changeusercoinBean.setBizCode("200202");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(20);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("false", result.get("success").toString(), "验证success");
			Logger.verifyEquals("3", changeusercoinCall.getString("Code"), "验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_ChangeUserCoin_019() {
		Logger.start(false, "抽奖扣除金币,只有去年金币扣成功");
		try {
			int uid = TestDataManager.getRandomIntNum(2)+1;
			ExpCallService.resetCoinAccount(uid);
			int coin=15;
			UserCoin uc=new UserCoin();
			uc.setCoin(coin);
			uc.setUserId(uid);
			uc.setYear(Integer.valueOf(YMTDateUtil.getSysTime("yyyy"))-1);
			ExpWapper.insertUserCoin(uc);
			Logger.comment("now_coin:"+coin);
			Integer c1 = ExpCallService.getUserCoin(uid);
			changeusercoinBean.setBizCode("200202");
			changeusercoinBean.setBizNo(YMTDateUtil.getSysTime("yyyyMMddHHmmssSSS"));
			changeusercoinBean.setUserId(uid);
			changeusercoinBean.setCoin(10);
			changeusercoinCall.setData(changeusercoinBean);
			changeusercoinCall.callService();
			JsonObject result = changeusercoinCall.getJsonObject().get("Data").getAsJsonObject();
			Logger.verifyEquals("true", result.get("success").toString(), "验证success");
			Logger.verifyEquals("0", changeusercoinCall.getString("BCode"), "验证BCode");
			Logger.verifyEquals(Math.abs(changeusercoinBean.getCoin()), changeusercoinCall.getCoin(), "验证coin");
			Integer c2 = ExpCallService.getUserCoin(uid);
			Logger.comment("now_coin:"+c2);
			Logger.verifyEquals(c1-c2,changeusercoinCall.getCoin(), "验证coin");
			verifyDB(changeusercoinBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}